import axios from '@/api/interceptor';
import { CategoryData, CategoryQuery } from './types';

export const getCategoryList = async () => {
  const result = await axios({
    url: '/categories/getCategoryList',
    method: 'GET',
  });
  return result.data;
};

export const selectPageCategory = async (params: CategoryQuery) => {
  const result = await axios({
    url: '/categories/listPage',
    method: 'GET',
    params,
  });
  return result.data;
};

export const editCategoryStatus = async (status: number, id: number) => {
  const result = await axios({
    url: `/categories/status`,
    method: 'PUT',
    params: { status, id },
  });
  return result.data;
};

export const deleteCategoryById = async (id: number) => {
  const result = await axios({
    url: `/categories/${id}`,
    method: 'DELETE',
  });
  return result.data;
};

export const createCategory = async (data: CategoryData) => {
  const result = await axios({
    url: '/categories/createCategory',
    method: 'POST',
    data,
  });
  return result.data;
};

export const editCategory = async (data: CategoryData) => {
  const result = await axios({
    url: '/categories/editCategory',
    method: 'PUT',
    data,
  });
  return result.data;
};

export const getCategoryDetail = async (id: number) => {
  const result = await axios({
    url: '/categories/getCategoryDetail',
    method: 'GET',
    params: { id },
  });
  return result.data;
};
